public class Solution24 {
    public ListNode swapPairs(ListNode head){
        ListNode dummyHead = new ListNode(0);
        dummyHead.next = head;
        ListNode prev = dummyHead;
        ListNode curr = head;
        while(curr != null || curr.next != null){
            ListNode node1 = curr;
            ListNode node2 = curr.next;
            node1.next = node2.next;
            node2.next = node1;
            prev.next = node2;
            prev = node1;
            curr = node1.next;
        }
        return dummyHead.next;
    }
}
